package Model.DateProfile;

import java.sql.Blob;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.Arrays;
import java.util.Date;
import java.util.ArrayList;
import java.awt.image.BufferedImage;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;

import javax.imageio.ImageIO;

import DBAccess.DBAccess;

public class PersonalInfo {

  private int height;
  private int weight;
  private int age;
  private Date birthdate;
  private ArrayList<String> activityInterests;
  private int gender;
  private int orientation;
  
public String getReligion() {
	return religion;
}

public void setReligion(String religion) {
	this.religion = religion;
}

public String getEthnicity() {
	return ethnicity;
}

public void setEthnicity(String ethnicity) {
	this.ethnicity = ethnicity;
}

private String religion;
  private String ethnicity;
  private String address;

  public PersonalInfo(int userID){
	  Statement st=null;
	  ResultSet rs=null;
	try {
		st = DBAccess.con.createStatement();
		rs = st.executeQuery("SELECT * FROM personaldb WHERE userID="+userID);
		if (rs.next()){
			setPersonalInfo(rs);
	    } else {
			this.setAddress("");
			this.setHeight(0);
			this.setWeight(0);
			this.setBirthdate(null);
			this.setInterests("");
			this.setOrientation(0);
			this.setReligion(null);
			this.setEthnicity(null);
			this.setGender(0);
	    }
	} catch (Exception e) {
		e.printStackTrace();
	}
	DBAccess.close(st, rs);
  }
	
	private void setPersonalInfo(ResultSet rs) throws SQLException, IOException{
		Blob img = rs.getBlob("profilePic");
		
		this.setAddress(rs.getString("address"));
		this.setHeight(rs.getInt("height"));
		this.setWeight(rs.getInt("weight"));
		this.setAge(rs.getInt("age"));
		this.setBirthdate(rs.getDate("birthdate"));
		this.setInterests(rs.getString("interests"));
		this.setOrientation(rs.getInt("orientation"));
		this.setReligion(rs.getString("religion"));
		this.setEthnicity(rs.getString("ethnicity"));
		this.setGender(rs.getInt("sex"));
	}

  public void setHeight(int height) {
	  this.height = height;
  }

  public void setWeight(int weight) {
	  this.weight = weight;
  }

  public void setAge(int age) {
	  this.age = age;
  }

  public void setBirthday(String date) {
	  this.birthdate = new Date(date);
  }

  public void setInterests(String interests) {
	  String list[] = interests.split(";");
	  this.activityInterests = new ArrayList<String>(Arrays.asList(list));
  }

  public void setGender(int gender) {
	  this.gender = gender;
  }

  public void setOrientation(int orientation) {
	  this.orientation = orientation;
  }
  public void setAddress(String address){
	  this.address = address;
  }
  public String getAddress(){
	  return this.address;
  }

public int getGender() {
	return gender;
}

public int getOrientation() {
	return orientation;
}

public void setBirthdate(Date birthdate) {
	this.birthdate = birthdate;
}

public void setActivityInterests(ArrayList<String> activityInterests) {
	this.activityInterests = activityInterests;
}

public int getHeight() {
	return height;
}

public int getWeight() {
	return weight;
}

public int getAge() {
	return age;
}

public Date getBirthdate() {
	return birthdate;
}

public ArrayList<String> getActivityInterests() {
	return activityInterests;
}
public String getInterests(){
	StringBuffer buf = new StringBuffer();
	for (int i=0; i<activityInterests.size();i++){
		buf.append(activityInterests.get(i));
		if (i<activityInterests.size()-1)
			buf.append(",");
	}
	
	return buf.toString();
//	return activityInterests.toString().replaceAll("[", "").replaceAll("]", "");

}
}